from alg import Solution
import time

def print_matrix(matrix):
    """打印矩阵"""
    for row in matrix:
        print(row)

def test_update_matrix():
    solution = Solution()
    
    # 测试用例1：2x2矩阵
    mat1 = [[0, 1],
            [1, 0]]
    print("测试用例1:")
    print("输入矩阵:")
    print_matrix(mat1)
    result1 = solution.updateMatrix(mat1)
    print("输出矩阵:")
    print_matrix(result1)
    print()
    
    # 测试用例2：3x3矩阵，中心为0
    mat2 = [[1, 1, 1],
            [1, 0, 1],
            [1, 1, 1]]
    print("测试用例2:")
    print("输入矩阵:")
    print_matrix(mat2)
    result2 = solution.updateMatrix(mat2)
    print("输出矩阵:")
    print_matrix(result2)
    print()
    
    # 测试用例3：全1矩阵
    mat3 = [[1, 1, 1],
            [1, 1, 1],
            [1, 1, 1]]
    print("测试用例3:")
    print("输入矩阵:")
    print_matrix(mat3)
    result3 = solution.updateMatrix(mat3)
    print("输出矩阵:")
    print_matrix(result3)
    print()
    
    # 测试用例4：全0矩阵
    mat4 = [[0, 0, 0],
            [0, 0, 0],
            [0, 0, 0]]
    print("测试用例4:")
    print("输入矩阵:")
    print_matrix(mat4)
    result4 = solution.updateMatrix(mat4)
    print("输出矩阵:")
    print_matrix(result4)
    print()

def performance_test():
    """性能测试"""
    solution = Solution()
    
    # 生成大规模测试用例
    import random
    size = 100
    mat = [[random.randint(0, 1) for _ in range(size)] for _ in range(size)]
    
    print(f"性能测试: {size}x{size} 矩阵")
    start_time = time.time()
    solution.updateMatrix(mat)
    end_time = time.time()
    print(f"执行时间: {end_time - start_time:.4f} 秒")

if __name__ == "__main__":
    print("01矩阵距离计算算法测试\n")
    test_update_matrix()
    print("\n性能测试:")
    performance_test() 